﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace C_sports_meet
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private Button oldButton = new Button();
        public MainWindow()
        {
            InitializeComponent();     
        }
        private bool isAdminVerified = false;
        private void button_Click(object sender, RoutedEventArgs e)
        {
              Button btn = e.Source as Button;
    string colorValue = "#409BB6";
    BrushConverter converter = new BrushConverter();
    Brush brush = (Brush)converter.ConvertFromString(colorValue);
    oldButton.Foreground = brush;
    btn.Foreground = Brushes.Red;
    oldButton = btn;

            // 检查页面是否是管理员页面并且管理员身份未验证过
            if ((btn.Tag.ToString() == "/Manager/InkPage.xaml" ||
             btn.Tag.ToString() == "/Manager/MAthlete.xaml" ||
             btn.Tag.ToString() == "/Manager/MJudge.xaml" ||
             btn.Tag.ToString() == "/Manager/MSubject.xaml" ||
             btn.Tag.ToString() == "/Manager/MVolunteer.xaml") &&
            !isAdminVerified)
            {
        // 创建对话框
        AuthenticationDialog dialog = new AuthenticationDialog();
        dialog.Left = this.Left + (this.Width - dialog.Width) / 2;
        dialog.Top = this.Top + (this.Height - dialog.Height) / 2;

        if (dialog.ShowDialog() == true)
        {
            string enteredIdentityCode = dialog.EnteredIdentityCode;

            // 进行身份码验证逻辑
            if (enteredIdentityCode == "345")
            {
                // 验证成功，设置管理员身份为已验证，并跳转到相应页面
                isAdminVerified = true;
                fram1.Source = new Uri(btn.Tag.ToString(), UriKind.Relative);
            }
            else
            {
                // 验证失败，显示错误消息或执行其他操作
                MessageBox.Show("身份验证失败！请重新输入身份码。");
            }
        }
    }
    else
    {
        // 非管理员页面或管理员身份已验证过，直接跳转到相应页面
        fram1.Source = new Uri(btn.Tag.ToString(), UriKind.Relative);
    }
        }
    }
}
